﻿/**
 * Created by Mark_ren on 2016/10/15.
 * 苟富贵,無相忘
 */

document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==27){ // 按 Esc
        //要做的事情
        //alert("苟富贵勿相忘");
    }
    if(e && e.keyCode==13){ // enter 键
        //要做的事情
        userLogin()
    }
};
//登录
function userLogin() {
    var loginName = $("#loginName").val().trim();;
    var passWord = $("#passWord").val().trim();
    if(loginName==null||loginName==''){
        alert("请输入登录帐号!");
        return;
    }
    if(passWord==null||passWord==''){
        alert("请输入密码!");
        return;
    }
    console.log(MD5(passWord));
    var login = $.Params.create();

        login.addParams("loginName",loginName);
        login.addParams("passWord",MD5(passWord));

        login.ajax(getIP()+"users/userLogin",function(data) {

            if (data.success==true) {
                var loginName = "";
                var roleId = "";
                $.each(data.result, function (i, val) {
                    loginName=val.loginName;
                    roleId = val.powerRoleId;

                });
               // alert("登录成功!");
			    window.localStorage.setItem("loginName",loginName);
                window.localStorage.setItem("roleId",roleId);
                window.location.href=getIP()+"index.html";
            }else{
                alert("用户名或密码不正确!");
            }

        });
}
